package cn.finder0519.networkspeedtest;

import java.io.IOException;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

public class NetworkUtils {

    public static boolean isInternetReachable() {
        try {
            URL url = new URL("https://speed.cloudflare.com/");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setRequestMethod("HEAD");
            connection.setConnectTimeout(5000);
            int responseCode = connection.getResponseCode();
            return responseCode == HttpsURLConnection.HTTP_OK;
        } catch (IOException e) {
            return false;
        }
    }
}
